package singleton;

/**
 * Created with IntelliJ IDEA.
 * ClassName: App
 * Package: singleton
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-13
 * Time: 15:48
 */

public class App {

    static HungrySingle hs1;
    static HungrySingle hs2;

    public static void main(String[] args) {

        Thread t1 = new Thread(){
            @Override
            public void run() {
                hs1 = HungrySingle.getInstance();
            }
        };

        Thread t2 = new Thread(){
            @Override
            public void run() {
                hs2 = HungrySingle.getInstance();
            }
        };
        t1.start();
        t2.start();

        //存在的问题是main线程执行很块 还没获取到就就执行完了
        //所以调用join方法 设置等待
        try {
            t1.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        try {
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        System.out.println(hs1);
        System.out.println(hs2);
        System.out.println(hs2 == hs1);


    }

}
